import { Config } from "../../src/config/Config";
import { DbConfig } from "../../src/config/DbConfig";
import { DaoBase } from "../../src/engine/dao/DaoBase";
import DateUtil from "../../src/engine/utils/DateUtil";
import { MysqlClient } from "../../src/engine/utils/MySqlClient";
import { MysqlManager } from "../../src/engine/utils/MysqlManager";

export class Club_Freeze_HistoryDao extends DaoBase {

    public static DB_NAME: string = DbConfig.Db_Name.db_admin;


    public static async insert_freeze_history(param: object) {
        let clubid: number = param["clubid"]
        let freezeid: number = param["freezeid"]
        let handleid: number = param["handleid"]
        let freeze_type: number = param["freeze_type"]
        let time: string = DateUtil.formatDateStr(DateUtil.now())
        let client: MysqlClient = await MysqlManager.instance.getDb(this.DB_NAME);
        let sql: string = 'INSERT INTO t_club_freeze_history(clubid,freezeid,handleid,freeze_type,time) VALUES(?,?,?,?,?) ;';
        let sqlParams = [clubid, freezeid, handleid, freeze_type, time];
        await client.queryPromise(sql, sqlParams);
    }

    public static async get_history(clubid: number) {
        let client: MysqlClient = await MysqlManager.instance.getDb(this.DB_NAME);
        let sql: string = "select * from v_club_freeze_history where clubid=? order by time desc"
        let sqlParams = [clubid];
        let rows = await client.queryPromise(sql, sqlParams);
        if (rows && rows.length) {
            return rows
        }
        return []
    }

    public static async clear(delete_time: number) {
        let client: MysqlClient = await MysqlManager.instance.getDb(this.DB_NAME);
        let sql: string = "delete from t_club_freeze_history where time < ?"
        let sqlParams = [DateUtil.formatDateStr(delete_time)];
        await client.queryPromise(sql, sqlParams);
    }

}